<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>MyBlog | 部门编辑</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../../static/build/css/app.min.css" th:href="${#fn.getStaticFile('/build/css/app.min.css')}">
    <link rel="stylesheet" href="../../static/dist/css/common.css" th:href="${#fn.getStaticFile('/dist/css/common.css')}">
    <script src="../../static/build/js/app.min.js" th:src="${#fn.getStaticFile('/build/js/app.min.js')}"></script>
    <script src="../../static/dist/js/common.js" th:src="${#fn.getStaticFile('/dist/js/common.js')}"></script>
    <script th:inline="javascript">
        $(function () {
            $("#btnSubmit").click(function(){
                $("#btnSubmit").attr("disabled",true);
                $("#departmentForm").submit();
            });
            $("#departmentForm").validate({
                rules: {
                    name: {remote: ctx + "sys/department/checkName?id=" + $("#id").val(), required: true},
                    parentId: {required: true}
                },
                messages: {
                    name: {required: "名称不能为空", remote: "名称已存在"},
                    parentId: {required: "分类不能为空"}
                },
                invalidHandler: function (form, validator) {
                    $("#btnSubmit").attr("disabled", false);
                }
            });
        });
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini " th:classappend="${#session.getAttribute('sidebarClass')}" th:with="pageCode='departmentForm'">
    <div class="wrapper">
    <!-- Main Header -->
    <div th:replace="fragment/layout :: header"></div>
    <!-- Left side column. contains the logo and sidebar -->
    <div th:replace="fragment/layout :: menu(activePageCode=${pageCode})"></div>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <!-- Nav tabs -->
            <ul th:replace="fragment/menuTab :: menuTab(activePageCode=${pageCode})"></ul>
            <div class="panel panel-info">
                <div th:if="${message!=null}"  th:class="'alert alert-'+${message.type}" th:text="${message.code}"></div>
                <div class="panel-body">
                    <div th:replace="fragment/validatorError :: validate(${bindingResult})"></div>
                    <form id="departmentForm" th:action="@{/sys/department/save}" method="post" class="form-horizontal">
                        <input type="hidden" id="id" name="id" th:value="${department.id}" />
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="name">名称</label>
                            <div class="col-sm-6">
                                <input id="name" name="name" class="form-control" th:value="${department.name}" autofocus />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="parentId">分类</label>
                            <div class="col-sm-6">
                                <select  id="parentId" name="parentId"  class="form-control " th:field="${department.parentId}">
                                    <option th:each="parentDep : ${departmentList}"   th:value="${parentDep.id}" th:text="${parentDep.fullName}">Credit card</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="hidden">是否隐藏</label>
                            <div class="col-sm-6">
                                <input type="radio" th:each="bool:${bools}" th:value="${bool.key}" th:text="${bool.value}" name="hidden" id="hidden" th:field="${department.hidden}" autofocus>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-9 col-sm-offset-3">
                                <button  type="button" class="btn btn-primary" id="btnSubmit">
                                    <span class="glyphicon glyphicon-ok"></span>保存
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <div th:replace="fragment/layout :: footer"></div>
</div>
</body>
</html>